import pymysql
class Db_Tolls(object):
    @classmethod
    def db_create_conn(cls):
        conn=pymysql.connect(host="",port="",user="",password="",database="",charset="")
        return conn
    @classmethod
    def db_query(cls,sql):
        try:
            my_connect=Db_Tolls.db_create_conn()
            my_cursor=my_connect.cursor()
            my_cursor.execute(sql)
            print("Affected rows",my_connect.affected_rows())
            res=my_cursor.fetchone()
        except Exception as e:
            print("错误类型",str(e))
        finally:
            my_cursor.close()
            my_connect.close()
        return res
    def ab_such(cls,sql):
        try:
            my_connect=Db_Tolls.db_create_conn()
            my_cursor=my_connect.cursor()
            my_cursor.execute(sql)
            print("Affected rows",my_connect.affected_rows())
            my_connect.commit()
        except Exception as e:
            print("错误类型",str(e))
        finally:
            my_connect.rollback()
            my_cursor.close()
            my_connect.close()





